import { _decorator, Component,Camera, Node,Asset, SystemEvent, Vec2, v2, Prefab, v3, instantiate, Vec3, RigidBodyComponent, find,PhysicsSystem, tween, Material, MeshRenderer } from 'cc';

import BaseView from '../../Script/game/BaseView';
import GDef from '../../Script/config/GDef';
const { ccclass, property } = _decorator;

@ccclass('preCell')
export class preCell extends BaseView {

    @property({
        type: MeshRenderer
    })
    meshRender: MeshRenderer = null;
    @property({
        type: Material
    })
    matNormal: Material = null;
    @property({
        type: Material
    })
    matSelected: Material = null;

    _id: number = -1;

    onLoad() {
        this.on(GDef.wdEvent.pressCell,this.pressCell);
        this.on(GDef.wdEvent.dragCell,this.dragCell);
    }

    setId(n: number) {
        this._id = n;
    }

    getId() {
        return this._id;
    }

    pressCell(cellFrom: number,cellTo: number,pos: Vec3){
        if(cellTo < 15)return;
        if(cellTo == this._id)this.meshRender.material = this.matSelected;
        else this.meshRender.material = this.matNormal;
    }
    dragCell(cellFrom: number,cellTo: number,pos: Vec3){
        if(cellTo < 15)return;
        if(cellTo == this._id)this.meshRender.material = this.matSelected;
        else this.meshRender.material = this.matNormal;
    }

    update(): void {
        let _v3_0: Vec3 = new Vec3(0, 0, 0);
        this.node.getWorldPosition(_v3_0);
        // this.node.setPosition(v3(Math.random() * 2 - 4,0.1,Math.random() * 2 - 4));
        
        
        // if (!this.lifeBarNode) return;
        // let _v3_0: Vec3 = new Vec3(0, 0, 0);
        // this.lifeBarParentNode.getWorldPosition(_v3_0);
        // GameEntity.mCamera.getComponent(CameraComponent).convertToUINode(_v3_0, this.lifeBarNode.parent, _v3_0);
        // this.lifeBarNode.setPosition(_v3_0);
        // let distance: any = Math.sqrt(Math.pow(this.node.position.x, 2) + Math.pow(this.node.position.z, 2));
        // this.lifeBarNode.getComponent(MonsterLifeBar).refresh(distance)
    }
}
